@isTest
private class WorkOrderHandeTest {
    static testMethod void testMethod1() {
        
          //产品结构
        ProductStructure__c ps1=new ProductStructure__c();
        ps1.Name='仪器';
        ps1.Classify1__c='生化';
        ps1.Classify2__c='生化-设备';
        ps1.Classify3__c='仪器';
        insert ps1;
        Brand__c brand = new Brand__c(
        	BrandShortName__c = '四川迈克'
        );
        insert brand;
          //产品
        Product__c p1=TestUtils.createProduct();
        p1.Name='仪器';
        p1.Category0__c = '仪器';
        p1.Model__c='Model1228';
        p1.ProductStructure__c=ps1.Id;
        p1.CRMBrand__c = brand.Id;
        p1.RecordTypeId =  Utils.getRecordTypeIdByDevNameAndObjName('NCProduct','Product__c');
        insert p1;

         Account acc=new Account();
        acc.Name='Test1229J';
        acc.Level__c = '一级医院';
        insert acc;
        Dealer__c d = new Dealer__c(
        	Only__c='Dealer__c'
        );
        insert d;


        Equipment__c eq = new Equipment__c();
        eq.Account__c = acc.Id;
        eq.IMEINumber__c = 'xxx321';
        eq.Product__c = p1.Id ; 
        eq.FromFlow__c = 1;
        insert eq;


        InstallationApply__c ins = new InstallationApply__c();
        ins.InstallationType__c='新装机';
        //必填字段 chatter 通知工作流引用到的字段都为必填字段
        ins.Instrument__c = p1.Id;
        ins.NEWDealer__c = d.Id;
        ins.Hospital__c = acc.Id;
        ins.InstallEstiDate__c = Date.newInstance(2017, 12, 1);
        ins.InstallsNumber__c = 1;
        ins.EffectiveTime__c = System.now();
        insert ins;
        

        Case cas=new Case();
        cas.AccountId=acc.Id;
        cas.InstallationApply__c = ins.Id;
        insert cas;




        WorkOrder__c wo=new WorkOrder__c();
        wo.Case__c=cas.Id;
        wo.Account__c=acc.Id;
        wo.Status__c='处理中';
        wo.ManufactureInfo__c=p1.Id;
        wo.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('InstallationOrder','WorkOrder__c');
        wo.WhetherToMakeASingle__c = '否';
        insert wo;
       
        
        System.Test.startTest();

        WorkOrder__c wo1=new WorkOrder__c();
        wo1.Case__c=cas.Id;
        wo1.Account__c=acc.Id;
        wo1.Status__c='完成';
        wo1.IMEINumber__c = 'x0003';
        wo1.ManufactureInfo__c=p1.Id;
        wo1.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NonAgentInstallationOrder','WorkOrder__c');
        insert wo1;

        

        WorkOrder__c wo2=new WorkOrder__c();
        wo2.Case__c=cas.Id;
        wo2.Account__c=acc.Id;
        wo2.Status__c='处理中';
        wo2.ServiceManufacture__c = [select Id from Equipment__c limit 1].Id;
        wo2.recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('ServiceOrder','WorkOrder__c');
        wo2.WhetherToMakeASingle__c = '否';
        insert wo2;

        wo2.Status__c = '完成';
        update wo2;

    }
}